//
//  GRDBViewController.swift
//  test-ios
//
//  Created by wyz5204 on 2023/4/1.
//

import UIKit
import GRDB


class GRDBViewController: ABaseViewController {
    
    
    private lazy var createDB = {
        return UIButton().then { view in
            view.setTitle("创建数据库", for: UIControl.State.normal)
            view.setTitleColor(UIColor.black, for: UIControl.State.normal)
        }
    }()
    
    
    private lazy var insertDB = {
        return UIButton().then { view in
            view.setTitle("插入数据", for: UIControl.State.normal)
            view.setTitleColor(UIColor.black, for: UIControl.State.normal)
        }
    }()
    
    private lazy var deleteDB = {
        return UIButton().then { view in
            view.setTitle("删除数据", for: UIControl.State.normal)
            view.setTitleColor(UIColor.black, for: UIControl.State.normal)
        }
    }()
    
    private lazy var updateDB = {
        return UIButton().then { view in
            view.setTitle("更新数据", for: UIControl.State.normal)
            view.setTitleColor(UIColor.black, for: UIControl.State.normal)
        }
    }()
    
    private lazy var queryDB = {
        return UIButton().then { view in
            view.setTitle("查询数据", for: UIControl.State.normal)
            view.setTitleColor(UIColor.black, for: UIControl.State.normal)
        }
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        // Do any additional setup after loading the view.
        createDB.addTo(self.view) { view -> UIButton in
            view.snp.makeConstraints { make in
                make.top.equalToSuperview().offset(100)
            }
            return view
        }.rx.tap.asDriver().drive (onNext: { element in
            print("创建数据库开始" ,  AppPersistancy.shared)
           
        }).disposed(by: rx.disposeBag)
        
        
        // Do any additional setup after loading the view.
        insertDB.addTo(self.view) { view -> UIButton in
            view.snp.makeConstraints { make in
                make.top.equalTo(createDB.snp.bottom).offset(100)
            }
            return view
        }.rx.tap.asDriver().drive (onNext: { element in
            print("插入 开始")
            AppPersistancy.shared.insertDBEntity()
        }).disposed(by: rx.disposeBag)
        
        
        
        // Do any additional setup after loading the view.
        deleteDB.addTo(self.view) { view -> UIButton in
            view.snp.makeConstraints { make in
                make.top.equalTo(insertDB.snp.bottom).offset(100)
            }
            return view
        }.rx.tap.asDriver().drive (onNext: { element in
            print("删除 开始")
        }).disposed(by: rx.disposeBag)
        
        
        // Do any additional setup after loading the view.
        updateDB.addTo(self.view) { view -> UIButton in
            view.snp.makeConstraints { make in
                make.top.equalTo(deleteDB.snp.bottom).offset(100)
            }
            return view
        }.rx.tap.asDriver().drive (onNext: { element in
            print("更新 开始")
        }).disposed(by: rx.disposeBag)
        
        
        // Do any additional setup after loading the view.
        queryDB.addTo(self.view) { view -> UIButton in
            view.snp.makeConstraints { make in
                make.top.equalTo(updateDB.snp.bottom).offset(100)
            }
            return view
        }.rx.tap.asDriver().drive (onNext: { element in
            print("查询 开始")
        }).disposed(by: rx.disposeBag)
    }
    
    
}


